/**请求封装
 * name:请求地址
 * data:传递得数据
 */
const service = ({name,data={}}) => {
	const loading = data.isLoading
	data.isLoading && delete data.isLoading
	// 返回一个promise对象
	return new Promise((resolve,rejects)=>{
		 !loading && uni.showLoading({
		      title: "加载中"
		    }) // 打开加载弹窗
		uniCloud.callFunction({
			name,
			data,
			success({result}) {
				if(result.code === 200) {
					resolve(result.data)
				} else {
					uni.showToast({
						icon:'none',
						title:result.msg
					})
				}
			},
			fail(err) {
				rejects(err)
			},
			complete() {
				!loading && uni.hideLoading()
			}
		})
	})
}

export default service